import * as actionTypes from './constant';
import { getRepairInfo, postRepairInfo, handleRepair } from '../../services';
import { message } from 'antd';

const changeRepairInfo = (res) => ({
    type:actionTypes.CHANGE_REPAIR_INFO,
    repairInfo: res.data
})

export const getRepairInfoAction = () => {
    return dispatch => {
        getRepairInfo().then(res => {
            // console.log(res);
            dispatch(changeRepairInfo(res));
        })
    }
}

export const postRepairInfoAction = (repairInfo) => {
    return dispatch => {
        postRepairInfo(repairInfo).then(res => {
            console.log(res);
            if(res.stutus == 200)
            {
                message.success("报修信息上传成功！")
            }else{
                message.error("报修信息上传失败！")
            }
        })
    }
}

export const handleRepairAction = (repair_id) => {
    return dispatch => {
        // console.log('handleRepair');
        handleRepair(repair_id).then(res => {
            // console.log(res)
            if(res.status == 200)
            {
                message.success(res.message)
            }
        })
    }

}